package com.company.huisuo.widget

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import com.company.huisuo.ext.dp2px

/**
 * GridLayoutManager Decoration
 */
class GridSpaceDecoration(
    private var horSpace: Int,
    private var verSpace: Int,
    private var column: Int
) : RecyclerView.ItemDecoration() {

    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        outRect.bottom = verSpace.dp2px()
        if (parent.getChildLayoutPosition(view) % 2 != 0) {
            outRect.left = horSpace.dp2px()
        }
        if (parent.getChildLayoutPosition(view) % column == 0) {
            outRect.left = 0
        }
    }
}